<script>
$(document).ready(function() {
    $( ".date" ).datepicker();
	$( ".date" ).datepicker( "option", "dateFormat", "dd-mm-yy");
	$( "#tgl_awal" ).change(function(){
			location.href = "<?php echo PENCABANG ?>list_result/"+$('#tgl_awal').val()+"/"+$('#tgl_akhir').val();
	});
	$( "#tgl_akhir" ).change(function(){
			location.href = "<?php echo PENCABANG ?>list_result/"+$('#tgl_awal').val()+"/"+$('#tgl_akhir').val();
	});
	list_table = $('#list_biaya').dataTable({
		"bFilter" : true,
		"bJQueryUI" : true,
		"aLengthMenu": [[10,25,50, 100, -1], [10,25,50,100, "Semua"]],
		"sPaginationType": "full_numbers",
		"oLanguage": {
			"sLengthMenu": "Menampilkan _MENU_ data",
			"sZeroRecords": "Belum ada data reservasi yang tersimpan",
			"sInfoFiltered": "(Hasil filter dari _MAX_ yang didapat)"
		}
	});
	$('#list_biaya_filter').hide();
	$('#filter_cabang').change( function () {
		asal = $( '#filter_cabang' ).val();
		if(asal=='SEMUA'){
			list_table.fnFilter( '',1 );
		}else{
			list_table.fnFilter( asal,1 );
		}
	} );
	$( "#cetak_pdf" ).click(function(){
		tgl_awal = $( "#tgl_awal" ).val();
		tgl_akhir = $( "#tgl_akhir" ).val();
		cabang = $( "#filter_cabang" ).val();
		location.href="<?php echo PENCABANG?>cetak_pdf/"+tgl_awal+"/"+tgl_akhir+"/"+cabang;
	});
	$( "#cetak_excel" ).click(function(){
		tgl_awal = $( "#tgl_awal" ).val();
		tgl_akhir = $( "#tgl_akhir" ).val();
		cabang = $( "#filter_cabang" ).val();
		location.href="<?php echo PENCABANG?>cetak_excel/"+tgl_awal+"/"+tgl_akhir+"/"+cabang;
	});
} );
</script>
<?php
$data['cur_parent_menu']='laporan';
$data['cur_selected_menu']='pencabang';
$this->load->view('template/menu_view',$data);
?>
<br/><br/><br/><br/><br/><br/>
<table width="1000" align="center">
	<tr>
		<td width="500">
			<?php 
				$opt['SEMUA']='SEMUA';
				$opt = array_merge($opt,$filter_cabang['nama_cabang']);
			?>
			Filter cabang : <?php echo form_dropdown('cabang', $opt,'','id="filter_cabang"')?>
		</td>
		<td width="500" align="left">
			Tgl Awal : <input type="text" class="date" id="tgl_awal" value="<?php echo $tgl_awal?>"/>
			Tgl Akhir : <input type="text" class="date" id="tgl_akhir" value="<?php echo $tgl_akhir?>"/>
		</td>
	</tr>
</table>
<br/>
Cetak : <span class="clicked" id="cetak_pdf">PDF</span> <span class="clicked" id="cetak_excel">Excel</span>
<br/>
<table id="list_biaya" width="100%" align="center" border="0">
	<thead>
		<tr>
			<th>No</th>
			<th>Nama</th>
			<th>Kode Cabang</th>
			<th>Alamat</th>
			<th>Telp</th>
			<th>Total Tiket</th>
			<th>Total Tiket Void</th>
			<th>Total Omset</th>
			<th>Total Discount</th>
			<th>Total Fee Agen</th>
			<th>Total Void</th>
			<th>Total Biaya Langsung</th>
			<th>Total Setor</th>
			<th>Total Biaya OP Awal</th>
			<th>Total Laba Kotor</th>
			<th>Aksi</th>
		</tr>
	</thead>
	<tbody>
		<?php for($i=0;$i<count($list_result);$i++){?>
		<tr>
			<td><?php echo $i+1?></td>
			<td><?php echo $list_result[$i]['cabang_keberangkatan']?></td>
			<td><?php echo $filter_cabang['kode_cabang'][$list_result[$i]['cabang_keberangkatan']]?></td>
			<td><?php echo $filter_cabang['alamat_cabang'][$list_result[$i]['cabang_keberangkatan']]?></td>
			<td><?php echo $filter_cabang['telp_cabang'][$list_result[$i]['cabang_keberangkatan']]?></td>
			<td><?php echo $list_result[$i]['total_penumpang']?></td>
			<td><?php echo $list_result[$i]['tiket_void']?></td>
			<td>Rp <?php echo number_format($list_result[$i]['total_omset'],0,',','.')?></td>
			<td>Rp <?php echo number_format($list_result[$i]['total_discount'],0,',','.')?></td>
			<td>Rp <?php echo number_format($list_result[$i]['fee_agen'],0,',','.')?></td>
			<td>Rp <?php echo number_format($list_result[$i]['total_void'],0,',','.')?></td>
			<td>Rp 
				<?php 
					if($biaya_langsung){
						echo number_format($biaya_langsung[$list_result[$i]['cabang_keberangkatan']],0,',','.');
					}else{
						echo number_format(0,0,',','.');
					}
				?>
			</td>
			<td>Rp <?php echo number_format($list_result[$i]['total_setoran'],0,',','.')?></td>
			<td>Rp 
				<?php 
					if(isset($biaya_opawal[$list_result[$i]['cabang_keberangkatan']])){
						echo number_format($biaya_opawal[$list_result[$i]['cabang_keberangkatan']],0,',','.');
					}else{
						echo number_format(0,0,',','.');
					}
				?>
			</td>
			<td>Rp <?php echo number_format($list_result[$i]['total_laba'],0,',','.')?></td>
			<td><a href="<?php echo PENCABANG ?>grafik_harian_omset_cabang/<?php echo $list_result[$i]['cabang_keberangkatan']?>">Grafik Omset Bulanan</a>|
                            <a href="<?php echo PENCABANG ?>grafik_bulanan_omset_cabang/<?php echo $list_result[$i]['cabang_keberangkatan']?>">Grafik Omset Tahunan</a>|
                            <a href="<?php echo PENCABANG ?>grafik_harian_produk_cabang/<?php echo $list_result[$i]['cabang_keberangkatan']?>">Grafik Produktivitas Bulanan</a>|
                            <a href="<?php echo PENCABANG ?>grafik_bulanan_produk_cabang/<?php echo $list_result[$i]['cabang_keberangkatan']?>">Grafik Produktivitas Tahunan</a>
                        </td>
		</tr>
		<?php }?>
	</tbody>
</table>